package wrapper

import (
	"context"
	"github.com/asim/go-micro/v3/client"
)


type CliWrapper struct {
	client.Client
}

func (c *CliWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error{
	//log.Println("client wrapper!!!")
	//限流名
	commandName := req.Service() + "." + req.Endpoint()

	//行为主体
	action := func() error {
		return c.Client.Call(ctx, req, rsp, opts...)
	}

	if HystrixLimit(commandName, req.Endpoint(), action) == nil {
		return nil
	}else{
		HystrixFallback(rsp)
		return nil
	}
}

func NewCliWrapper(c client.Client) client.Client{
	return &CliWrapper{c}
}